package com.jf.net.entity

import com.jf.net.core.IError
import com.jf.net.core.IResponse
import com.jf.net.core.StatusValue

/**
 * ResponseResult
 * @author JackyFlame
 * @time 2023/10/20 15:42
 * @description
 */
open class ResponseResult<Data>(private val status: Int, private val responseBody: Data?, private val errors: IError?) : IResponse<Data> {

    companion object {
        fun <Data> success(responseBody: Data?): ResponseResult<Data> {
            return ResponseResult(StatusValue.SUCCESS, responseBody, null)
        }

        fun <Data> failure(errors: IError?): ResponseResult<Data> {
            return failure(null, errors)
        }

        fun <Data> failure(responseBody: Data?, errors: IError?): ResponseResult<Data> {
            return ResponseResult(StatusValue.FAILURE, responseBody, errors)
        }
    }

    override fun isSuccess(): Boolean = getStatus() == StatusValue.SUCCESS

    override fun getData(): Data? = this.responseBody

    override fun getError(): IError? = this.errors

    override fun getStatus(): Int = this.status
}